/**
 *  定义多个可以直接更改state里面数据的方法
 * 
 * 
 */
import {
  RECEIVE_ADDRESS,
  RECEIVE_CATEGORYS,
  RECEIVE_SHOPS,
  RECEIVE_USER_INFO,
  RESET_USER_INFO,
  RECEIVE_GOODS,
  RECEIVE_RATINGS,
  RECEIVE_INFO,
  INCREMENT_FOOD_COUNT,
  DECREMENT_FOOD_COUNT,
  
} from './mutation-types'

export default {
  //5k 的代码
  [RECEIVE_ADDRESS](state, data) {
    // console.log(data)
    state.address = data.address

  },
  [RECEIVE_CATEGORYS](state, data) {
    state.categorys = data.categorys

  },
  [RECEIVE_SHOPS](state, data) {
    state.shops = data.shops

  },

  //8k的代码
  // [RECEIVE_ADDRESS](state ,{address}) {
  //     state.address=address

  // },
  // [RECEIVE_CATEGORYS](state ,{categorys}) {
  //     state.categorys=categorys

  // },
  // [RECEIVE_SHOPS](state ,{shops}) {
  //     state.shops=shops

  // },

  // 退出的时候清空userInfo
  [RESET_USER_INFO](state) {
    alert('退出xxx')
    state.userInfo = {}
  },


// 登录的时候存储 userInfo信息
[RECEIVE_USER_INFO](state,{userInfo}){
  console.log('userInfo',userInfo)
  state.userInfo=userInfo
},



[RECEIVE_INFO](state,{ info }) {

  state.info = info

},


[RECEIVE_RATINGS](state,{ ratings }) {
  state.ratings = ratings

},


[RECEIVE_GOODS](state,{ goods }) {

  state.goods = goods
},

// 加
[INCREMENT_FOOD_COUNT](state,{ food }) {

  state.food = food
},
// 减
[DECREMENT_FOOD_COUNT](state,{ food }) {

 if(food.count==0){
   let index=state.shopCart.findIndex((item=>item.count==0))
   state.shopCart.splice(index,1)
 }
},


}
